package us.sunrisemorning.pixivbrower.dao;

import java.util.List;

import org.apache.commons.lang3.StringUtils;

import us.sunrisemorning.pixivbrower.model.Illust;

public class IllustService {
    public final Illust dao = new Illust().dao();

    public List<Illust> findByKeyword(String keyword, boolean r18) {
        if (r18) {
            if (StringUtils.isBlank(keyword)) {
                return dao.find("select * from illust where id in (select illustid from tag where tagname='R-18') order by bookmark desc");
            } else {
                return dao.find("select * from illust where id in (select illustid from tag where tagname=?) and id in (select illustid from tag where tagname='R-18') order by bookmark desc", keyword);
            }
        } else {
            if (StringUtils.isBlank(keyword)) {
                return dao.find("select * from illust order by bookmark desc");
            } else {
                return dao.find("select * from illust where id in (select illustid from tag where tagname=?) order by bookmark desc", keyword);
            }
        }
    }
}
